'''
Created on 15-Jul-2010

@author: dexen
'''

import os
import sys
import time

import rpyc

import dexen
from dexen.system.base import service

import constants
import feedback
import development
import eval_energy
import eval_daylight
import initialization
import imaging
import traceback

#--------------------------------------------------------------------------------
# MAIN SCRIPT
#--------------------------------------------------------------------------------
def main():
    spec = dexen.DexenSpec("Spec1")
    spec.register_init(initialization.InitializationTask)
    spec.register_task("Dev", development.DevelopmentTask, 1)
    #spec.register_task(imaging.ImagingTask, 1)
    spec.register_task("Eval_E", eval_energy.EvalEnergyTask, 1)
    spec.register_task("Eval_D", eval_daylight.EvalDaylightTask, 1)
    spec.register_task("Feedback", feedback.FeedbackTask, constants.POP_SIZE * 2)
    spec.set_max_num_births(constants.MAX_NUM_BIRTHS)
    
    schema_dir = os.getcwd()
    spec.set_schema("OVH1", schema_dir)
    
    for task in spec.tasks:
        print task

    conn = rpyc.connect(sys.argv[1], service.REGISTRY_PORT,
                        config=service.default_config) 
    addr = conn.root.get_node_mgr_addr()
    conn.close()
                
    try:
        conn = rpyc.connect(addr[0], addr[1],
                            config=service.default_config)    
        conn.root.run_schema(spec)
    except:
        print "There is an exception 2"
        traceback.print_exc(limit="100")
        

if __name__ == "__main__":
    main()
    
